//
//  AzkariCarouselView.m
//  Azkar
//
//  Created by 王易 on 2018/8/24.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "AzkariCarouselView.h"
#import "NewPagedFlowView.h"
#import "PrayViewController.h"

/**
 祈福轮番View
 */
@interface AzkariCarouselView()<NewPagedFlowViewDelegate, NewPagedFlowViewDataSource>

@property (nonatomic,weak) NewPagedFlowView *pageFlowView;

@end
@implementation AzkariCarouselView

- (instancetype)init
{
    if (self == [super init]) {
        
        NewPagedFlowView *pageFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * 9 / 16)];
        self.pageFlowView = pageFlowView;
        pageFlowView.delegate = self;
        pageFlowView.dataSource = self;
        pageFlowView.minimumPageAlpha = 0.1;
        pageFlowView.isCarousel = YES;
        pageFlowView.isOpenAutoScroll = YES;
        pageFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
        pageFlowView.isOpenAutoScroll = YES;
        [self addSubview:pageFlowView];
        
    }
    return self;
}

#pragma mark NewPagedFlowView Delegate
- (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
    return CGSizeMake(ScreenWidth - 60, (ScreenWidth - 60) * 9 / 16);
}

- (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
    
    NSLog(@"点击了第%ld张图",(long)subIndex + 1);
    UINavigationController *nav = [UINavigationController currentNC];
    PrayViewController *ctr = [PrayViewController new];
    ctr.publicModel = self.public_bless[subIndex];
    [FIRAnalytics logEventWithName:@"du_click_banner"
                        parameters:@{@"id":ctr.publicModel.ID?ctr.publicModel.ID:@"1"}];
    
    ctr.hidesBottomBarWhenPushed = YES;
    [nav pushViewController:ctr animated:YES];
    
//        RouteToPageWithInfo(@"PrayViewController", @{@"publicModel":self.public_bless[subIndex]});
//    self.indicateLabel.text = [NSString stringWithFormat:@"点击了第%ld张图",(long)subIndex + 1];
}

- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
    
    NSLog(@"ViewController 滚动到了第%ld页",pageNumber);

    
}
- (void)setPublic_bless:(NSArray<Public_BlessModel *> *)public_bless
{
    _public_bless = public_bless;
    
    [self.pageFlowView reloadData];
}
#pragma mark NewPagedFlowView Datasource
- (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
    
    return self.public_bless.count;
    
}

- (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
    PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
    if (!bannerView) {
        bannerView = [[PGIndexBannerSubiew alloc] init];
        bannerView.tag = index;
        bannerView.layer.cornerRadius = 4;
        bannerView.layer.masksToBounds = YES;
    }
    
    Public_BlessModel *model = self.public_bless[index];
    //在这里下载网络图片
      [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.bless_background] placeholderImage:[UIImage imageNamed:@"place_holder1"]];
//    bannerView.mainImageView.image = self.imageArray[index];
    
    return bannerView;
}

- (void)onAppLayoutDirectionSettingChanged:(NSNotification *)notification
{
    [MyBaseLayout setIsRTL:YES];
}
@end
